{include file="public/layout" /}

<body style="background-color: rgb(255, 255, 255); overflow-y: scroll; cursor: default; -moz-user-select: inherit;min-width:auto;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="min-width:auto;">
    {include file="member/bar" /}
    <div class="flexigrid">
        <div class="mDiv">
            <div class="ftitle">
                <h3>订单列表</h3>
                <h5>(共{$pageObj->totalRows}条记录)</h5>
            </div>
            <div title="刷新数据" class="pReload"><i class="fa fa-refresh"></i></div>
            <form class="navbar-form form-inline" id="postForm" action="{:url('Shop/index')}" method="get" onsubmit="layer_loading('正在处理');">
                {$searchform.hidden|default=''}
                <div class="sDiv">
                    <!-- 订单状态查询 -->
                    <div class="sDiv2 fl" style="margin-right: 6px;">  
                        <select name="order_status" class="select" style="margin:0px 5px;" onchange="OrderQueryStatus();">
                            <option value="">查看全部</option>
                            {volist name="$OrderStatus" id="vo"}
                                <option value="{$vo.order_status}" {eq name="$Request.param.order_status" value="$vo.order_status"}selected{/eq}>{$vo.status_name}</option>
                            {/volist}
                        </select>
                    </div>
                    <!-- 订单号查询 -->
                    <div class="sDiv2 fl" style="margin-right: 6px;">
                        <input type="text" size="50"  name="order_code" class="qsbox" style="width: 200px;" value="{$Request.param.order_code}" placeholder="搜索订单号...">
                        <input type="submit" class="btn" value="搜索">
                    </div>
                    {include file="shop/shop_bar" /}
                </div>
            </form>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                    <tr>
                        <th class="sign w40" axis="col0">
                            <div class="tc">选择</div>
                        </th>
                        <th abbr="article_title" axis="col3" class="">
                            <div style="text-align: left; padding-left: 10px;" class="">订单号</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">订单金额</div>
                        </th>
                        <!--<th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">支付方式</div>
                        </th>-->
                        <th abbr="article_time" axis="col6" class="w100">
                            <div class="tc">订单状态</div>
                        </th>
                        <th abbr="article_time" axis="col6" class="w160">
                            <div class="tc">下单时间</div>
                        </th>
                        <!--<th abbr="article_time" axis="col6" class="w160">
                            <div class="tc">支付时间</div>
                        </th>-->
                        <th axis="col1" class="w160">
                            <div class="tc">操作</div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                    {empty name="list"}
                        <tr>
                            <td class="no-data" align="center" axis="col0" colspan="50">
                                <i class="fa fa-exclamation-circle"></i>没有符合条件的记录
                            </td>
                        </tr>
                    {else/}
                        {volist name="list" id="vo"}
                        <tr>
                            <td class="sign">
                                <div class="w40 tc"><input type="checkbox" name="ids[]" value="{$vo.order_id}"></div>
                            </td>
                            <td class="" style="width: 100%;">
                                <div class="tl" style="padding-left: 10px;">
                                    <a href="{:url('Shop/order_details',array('order_id'=>$vo['order_id']))}">{$vo.order_code}</a>
                                </div>
                            </td>
                            <td class="">
                                <div class="w100 tc">
                                    ￥{$vo.order_amount}
                                </div>
                            </td>
                            <!--
                            <td class="">
                                <div class="w100 tc">
                                    {eq name="$vo.payment_method" value="1"}
                                        {$vo.pay_name}
                                    {else/}
                                        {$pay_method_arr[$vo.pay_name]|default='未支付'}
                                    {/eq}
                                </div>
                            </td>
                            -->
                            <td class="">
                                <div class="w100 tc">
                                    {$admin_order_status_arr[$vo.order_status]|default=''}
                                </div>
                            </td>
                            <td class="">
                                <div class="w160 tc">
                                    {$vo.add_time|MyDate='Y-m-d H:i:s',###}
                                </div>
                            </td>
                            <!--
                            <td class="">
                                <div class="w160 tc">
                                    {empty name="$vo.pay_time"}
                                        ————————
                                    {else/}
                                        {$vo.pay_time|MyDate='Y-m-d H:i:s',###}
                                    {/empty}
                                </div>
                            </td>
                            -->
                            <td>
                                <div class="w160 tc">
                                    <a href="{:url('Shop/order_details',array('order_id'=>$vo['order_id']))}" class="btn blue"><i class="fa fa-pencil-square-o"></i>详情</a>
                                    {eq name="$vo.order_status" value='0'}
                                        <!-- 订单未付款时出现 -->
                                        <a href="JavaScript:void(0);" onclick="OrderMark('yfk','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>付款
                                        </a>

                                        <a href="JavaScript:void(0);" onclick="OrderMark('gbdd','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>关闭
                                        </a>
                                    {/eq}

                                    {eq name="$vo.order_status" value='1'}
                                        <!-- 订单待发货时出现 -->
                                        <a href="JavaScript:void(0);" data-url="{:url('Shop/order_send', ['order_id'=>$vo.order_id])}" onclick="OrderSend(this);" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>发货
                                        </a>

                                        <a href="JavaScript:void(0);" onclick="OrderMark('gbdd','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>关闭
                                        </a>
                                    {/eq}

                                    {eq name="$vo.order_status" value='2'}
                                        <!-- 订单已发货时出现 -->
                                        <a href="JavaScript:void(0);" onclick="OrderMark('ysh','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>完成
                                        </a>

                                        <a href="JavaScript:void(0);" onclick="OrderMark('gbdd','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>关闭
                                        </a>
                                    {/eq}

                                    {if condition="-1 == $vo.order_status or 4 == $vo.order_status"}
                                        <!-- 订单取消或取消过期时出现 -->
                                        <a href="JavaScript:void(0);" onclick="OrderMark('ddbz','{$vo.order_id}','{$vo.users_id}','{$vo.admin_note}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>备注
                                            <input type="hidden" id="beizhu-url" value="{:url('Shop/update_note')}">
                                        </a>

                                        <a href="JavaScript:void(0);" onclick="OrderMark('ddsc','{$vo.order_id}','{$vo.users_id}');" class="btn blue">
                                            <i class="fa fa-pencil-square-o"></i>删除
                                        </a>
                                    {/if}
                                </div>
                            </td>
                        </tr>
                        {/volist}
                    {/empty}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        <div class="tDiv">
            <div class="tDiv2">
                <div class="fbutton checkboxall">
                    <input type="checkbox" onclick="javascript:$('input[name*=ids]').prop('checked',this.checked);">
                </div>
                <div class="fbutton">
                    <a onclick="batch_del(this, 'ids');" data-url="{:url('Shop/order_del')}">
                        <div class="add" title="批量删除">
                            <span><i class="fa fa-close"></i>批量删除</span>
                        </div>
                    </a>
                </div>
            </div>
            <div style="clear:both"></div>
        </div>
        <!--分页位置-->
        {$pageStr}
    </div>
</div>
<script>
    $(document).ready(function(){
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function(){
            $(this).toggleClass('trSelected');
        });

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        {eq name="$is_syn_theme_shop" value="1"}
            syn_theme_shop();
        {/eq}
        function syn_theme_shop()
        {
            layer_loading('订单初始化');
            // 确定
            $.ajax({
                type : 'get',
                url : "{:url('Shop/ajax_syn_theme_shop')}",
                data : {},
                dataType : 'json',
                success : function(res){
                    layer.closeAll();
                    if(res.code == 1){
                        layer.msg(res.msg, {icon: 1, time: 1000});
                    }else{
                        layer.alert(res.msg, {icon: 2, title:false}, function(){
                            window.location.reload();
                        });
                    }
                },
                error: function(e){
                    layer.closeAll();
                    layer.alert('网络失败，请刷新页面后重试', {icon: 2, title:false}, function(){
                        window.location.reload();
                    });
                }
            })
        }
    });

    function OrderQueryStatus(){
        $('#postForm').submit();
    }

    function OrderSend(obj){
        var url = $(obj).attr('data-url');

        // iframe窗
        var iframes = layer.open({
            type: 2,
            title: '订单发货详情',
            fixed: true, //不固定
            shadeClose: false,
            shade: 0.3,
            area: ['100%', '100%'],
            content: url
        });
        layer.full(iframes);
    }

    // 订单操作
    function OrderMark(status_name,order_id,users_id,admin_note){
        if('yfk' == status_name){
            var msg = '确认订单已付款？';
        }else if('ysh' == status_name){
            var msg = '确认订单已收货？';
        }else if('gbdd' == status_name){
            var msg = '确认关闭订单？';
        }else if('ddbz' == status_name){
            layer.prompt({
                formType: 2,
                value: admin_note,
                title: false,
                area: ['300px', '100px']
            }, function(value, index, elem){
                UpNote(order_id,value);
                layer.close(index);
            });
            
            return false;
        }else if('ddsc' == status_name){
            var msg = '确认删除订单？';
        }

        layer.confirm(msg, {
            title:false,
            btn: ['确定','取消'],
        },function(){
            $.ajax({
                url: "{:url('Shop/order_mark_status')}",
                data: {order_id:order_id,status_name:status_name,users_id:users_id},
                type:'post',
                dataType:'json',
                success:function(res){
                    layer.closeAll();
                    if ('1' == res.code) {
                        layer.msg(res.msg, {time: 1500},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg, {time: 1500});
                    }
                }
            });
        },function(index){
            layer.closeAll(index);
        });
    }

    function UpNote(order_id,admin_note){
        $.ajax({
            url: "{:url('Shop/update_note')}",
            data: {order_id:order_id,admin_note:admin_note},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if ('1' == res.code) {
                    layer.msg(res.msg, {time: 1500},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(res.msg, {time: 1500});
                }
            }
        });
    }
</script>

{include file="public/footer" /}